package com.dz;

import com.dz.properties.StorageProperties;
import com.dz.template.AliyunOSSTemplate;
import com.dz.template.MinioTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@EnableConfigurationProperties(StorageProperties.class)
public class StorageAutoConfiguration {
    @Bean
    @ConditionalOnProperty(name = "storage.type", havingValue = "minio")//配置文件中存在指定属性名与值，才会将bean加入IOC容器
    public MinioTemplate Template(StorageProperties storageProperties) {

        MinioTemplate minioTemplate = new MinioTemplate();
        minioTemplate.setMinioProperties(storageProperties);
        return minioTemplate;
    }

    @Bean
    @ConditionalOnProperty(name = "storage.type", havingValue = "oss")//配置文件中存在指定属性名与值，才会将bean加入IOC容器
    public AliyunOSSTemplate aliyunOSSTemplate(StorageProperties storageProperties) {

        AliyunOSSTemplate aliyunOSSTemplate = new AliyunOSSTemplate();
        aliyunOSSTemplate.setAliyunOSSProperties(storageProperties);
        return aliyunOSSTemplate;
    }
}
